package com.dabai.app.im;

import android.content.Context;
import android.os.Handler;
import android.webkit.JavascriptInterface;

import de.greenrobot.event.EventBus;

/***
 * APP提供给webview的通用接口 Created By Zhangxiliang Date：2014年9月4日 Version： 2.0
 * Copyright (c) 2014 56.com Software corporation All Rights Reserved.
 */
public class BaseJsObject extends Object {
    private Context mContext;
    private Handler mHandler;
    private JunHuaWebView junHuaWebView;

    private JSCallBarListener jsCallBarListener;

    public BaseJsObject(Context mContext, JunHuaWebView junHuaWebView) {
        this.mContext = mContext;
        mHandler = new Handler();
        this.junHuaWebView = junHuaWebView;
    }

    @JavascriptInterface
    public JSCallBarListener getJsCallBarListener() {
        return jsCallBarListener;
    }

    @JavascriptInterface
    public void setJsCallBarListener(JSCallBarListener jsCallBarListener) {
        this.jsCallBarListener = jsCallBarListener;
    }

    @JavascriptInterface
    public void showShareIcon(int isShow) {
        ShowShareEvent showShareEvent = new ShowShareEvent();
        if (isShow == 0) {
            showShareEvent.setShow(false);
        } else {
            showShareEvent.setShow(true);
        }
        EventBus.getDefault().post(showShareEvent);
    }

    @JavascriptInterface
    public void wechatShare(String title, String imageUrl, String shareContent, String shareUrlLink) {
        ShareParameters shareParameters = new ShareParameters();
        shareParameters.setTitle(title);
        shareParameters.setShareUrlLink(shareUrlLink);
        shareParameters.setShareContent(shareContent);
        shareParameters.setImageUrl(imageUrl);
        EventBus.getDefault().post(shareParameters);
    }

    @JavascriptInterface
    public void DSWebViewTitle(String title) {
        EventBus.getDefault().post(new WebViewTitleEvent(title));
    }

    public interface JSCallBarListener {
        void onRightBarItem(String title, String type);
    }

}
